module-definition
Determines the module definition type (CommonJS, AMD, ES6, or none) for a given JavaScript file
by walking through the AST.
npm install module-definition
Usage
const getModuleType = require('module-definition');
getModuleType('myscript.js', (err, type) => {
console.log(type);
});
let type = getModuleType.sync('myscript.js');
console.log(type);
type = getModuleType.fromSource('define({foo: "foo"});');
console.log(type);
Passes one of the following strings to the given callback or returns the string in sync API:
When specifying a filename, using the sync or async API, you can also provide an options
object with an alternative fs
implementation used to read the source file with.
const myFs = GetFs();
const options = {fileSystem: myFs}
getModuleType('myscript.js', (err, type) => {
console.log(type);
}, options);
const type = getModuleType.sync('myscript.js', options);
Via shell command (requires a global install: npm install -g module-definition
)
module-definition filename